//
//  TabView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/22.
//

#import "TabView.h"
#import "CommonUtil.h"

@interface TabView()

@property (strong, nonatomic) UIButton * selectBtn;

@property (strong, nonatomic) UIView * topLine;
@property (strong, nonatomic) UIView * bottomLine;
@property (strong, nonatomic) UIView * leftLine;
@property (strong, nonatomic) UIView * rightLine;
@end

@implementation TabView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        
        
        self.myStatistics = [self createTabBtnWithTitle:@"我的统计"];
        self.myStatistics.frame = CGRectMake(0, 0, SCREEN_WIDTH/3, self.height);
        self.allStatistics = [self createTabBtnWithTitle:@"全网统计"];
        self.allStatistics.frame = CGRectMake(self.myStatistics.right, 0, SCREEN_WIDTH/3, self.height);
        self.expertStatistics = [self createTabBtnWithTitle:@"专家统计"];
        self.expertStatistics.frame = CGRectMake(self.allStatistics.right, 0, SCREEN_WIDTH/3, self.height);
        
        
        [self addSubview:self.myStatistics];
        [self addSubview:self.allStatistics];
        [self addSubview:self.expertStatistics];
        
        [self addSubview:self.topLine];
        [self addSubview:self.bottomLine];
        [self addSubview:self.leftLine];
        [self addSubview:self.rightLine];
        
        [self tabBtnClick:self.myStatistics];
    }
    return self;
}

- (UIButton *)createTabBtnWithTitle:(NSString *)btnTitle{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:btnTitle forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(tabBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    return btn;
}

- (void)tabBtnClick:(UIButton *)target{
    
    self.selectBtn.selected = false;
    self.selectBtn.backgroundColor = [UIColor whiteColor];
    self.selectBtn = target;
    self.selectBtn.selected = YES;
    self.selectBtn.backgroundColor = RGB(255.0, 89.0, 117.0);
    
}


#pragma mark - lazy

-(UIView *)topLine{
    if (!_topLine) {
        _topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, AD(1))];
        _topLine.backgroundColor = [UIColor grayColor];
    }
    return _topLine;
}

-(UIView *)bottomLine{
    if (!_bottomLine) {
        _bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, self.height-AD(1), SCREEN_WIDTH, AD(1))];
        _bottomLine.backgroundColor = [UIColor grayColor];
    }
    return _bottomLine;
}

-(UIView *)leftLine{
    if (!_leftLine) {
        _leftLine = [[UIView alloc] initWithFrame:CGRectMake(_myStatistics.right, 0, AD(1), self.height)];
        _leftLine.backgroundColor = [UIColor grayColor];
    }
    return _leftLine;
}

-(UIView *)rightLine{
    if (!_rightLine) {
        _rightLine = [[UIView alloc] initWithFrame:CGRectMake(_allStatistics.right, 0, AD(1), self.height)];
        _rightLine.backgroundColor = [UIColor grayColor];
    }
    return _rightLine;
}



@end
